import { defineStore } from 'pinia';
import { ref } from 'vue';

export const useUserStore = defineStore('pinia', {
  state: () => ({
    userInfo: null,
  }),
  actions: {
    setUserInfo(user) {
      this.userInfo = user;
    },
    clearUserInfo(){
        this.userInfo = null
    }
  },
  getters:{
    isCreated:(state)=> !!state.userInfo
  }
});

export const useThemeStore = defineStore('theme', () => {
  const isDarkMode = ref(false);

  const toggleDarkMode = () => {
    isDarkMode.value = !isDarkMode.value;
    if (isDarkMode.value) {
      document.documentElement.classList.add('dark-mode');
    } else {
      document.documentElement.classList.remove('dark-mode');
    }
  };

  return { isDarkMode, toggleDarkMode };
});
